package com.ccs.testdatas;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import com.ccs.functions.Login;
import com.ccs.functions.PatientName;

public class Dasoss {

	public void dasoss(WebDriver driver) throws Exception{
		driver.manage().window().maximize();
		Login in = new Login();
		in.hcs(driver, "dasoss");
		driver.findElement(By.xpath("//a[contains(.,'DAS OSS')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		
		driver.findElement(By.xpath("//div[@id='defaultOptions']/input[1]")).sendKeys("Cocolife");
		//driver.findElement(By.xpath("//div[@id='defaultOptions']/input[1]")).sendKeys("ValueCare");
		driver.findElement(By.xpath("//div[@id='defaultOptions']/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[contains(.,'Outpatient Registration')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//OUTPATIENT REGISTRATION
		PatientName name = new PatientName();
		double num =  Math.floor((Math.random()*9999)+1);
		String code = String.valueOf(num);
		code = code.replaceAll("\\.","");
		driver.findElement(By.xpath("//input[@id='name.firstName']")).sendKeys("Cocolife"+code);
		//driver.findElement(By.xpath("//input[@id='name.firstName']")).sendKeys("ValueCare"+code);
		String middle = name.names(2);
		driver.findElement(By.xpath("//input[@id='name.middleName']")).sendKeys(middle);
		Select suffix = new Select(driver.findElement(By.xpath("//select[@id='suffix.code']")));
		suffix.selectByVisibleText("JR");
		driver.findElement(By.xpath("//input[@id='birthDate']")).sendKeys("01/01/1995");
		driver.findElement(By.xpath("//input[@id='gender1']")).click();
		driver.findElement(By.xpath("//input[@id='presentAddrNumStreet']")).sendKeys("E. Rodriquez");
		driver.findElement(By.xpath("//input[@id='presentAddrBldg']")).sendKeys("St. Luke's");
		Select city = new Select(driver.findElement(By.xpath("//select[@id='presentAddrCitySelect']")));
		city.selectByVisibleText("MANILA CITY");
		driver.findElement(By.xpath("//input[@id='presentAddrProvince']")).sendKeys("Metro Manila");
		driver.findElement(By.xpath("//input[@id='presentAddrPostalCode']")).sendKeys("1800");
		
		//SUBMIT FORM
		driver.findElement(By.xpath("//div[@id='controls']/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//GO TO ORDER PAGE
		driver.findElement(By.xpath("//div[@id='controls']/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//GUARANTOR TOGGLE
		WebElement guarantor = driver.findElement(By.xpath("//a[@id='guarantorToggle']"));
		guarantor.click();
		Select accountClass = new Select(driver.findElement(By.xpath("//select[@id='opsGuarantorBean.accountClassStr']")));
		accountClass.selectByVisibleText("HMO");
		driver.findElement(By.xpath("//input[@id='findGuarantor']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='bp_entity_finder_key']")).sendKeys("cocolife");
		//driver.findElement(By.xpath("//input[@id='bp_entity_finder_key']")).sendKeys("Value Care Health");
		driver.findElement(By.xpath("//div[@id='bpFinderForm']/div[2]/div[1]/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select relationship = new Select(driver.findElement(By.xpath("//select[@id='relationship']")));
		relationship.selectByVisibleText("GUARANTOR");
		driver.findElement(By.xpath("//input[@id='percent']")).click();
		driver.findElement(By.xpath("//input[@id='percentageLimit']")).clear();
		driver.findElement(By.xpath("//input[@id='percentageLimit']")).sendKeys("100");
		driver.findElement(By.xpath("//input[@id='add']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//ORDER TOGGLE
		WebElement order = driver.findElement(By.xpath("//a[@id='orderToggle']"));
		order.click();
		driver.findElement(By.xpath("//input[@id='mServiceCode']")).sendKeys("042910010");
		driver.findElement(By.xpath("//div[@id='item_btn_div']/input[1]")).click();
		Thread.sleep(5000);
		//driver.findElement(By.xpath("//div[@class='finderFormContents']/div[1]/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='orderDoctorCode']")).sendKeys("7112");
		driver.findElement(By.xpath("//input[@name='orderDF']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='addOrder']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//SUBMIT FORM
		driver.findElement(By.xpath("//input[@id='submitForm']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
	}
	
	
}
